
<body>

<div class="hd">
    <div class="warp">

        <a href="./">
            <img src="<?php echo $base_url?>static/dist/images/logo.png" alt="" class="logo-img">
            <span class="span_txt">商城首页</span>
        </a>

    </div>
</div>
<div class="login-box">
    <div class="bg" style="background-image:url(<?php echo $base_url?>static/dist/images/login_bg.jpg)">
        <div class="warp">
            <div class="form-box czmm">
                <div class="cont-box">
                    <!--登录-->
                    <div class="cont-item active">
                        <div class="input-txt">
                            <i class="iconfont icon-shouji"></i>
                            <input type="text" placeholder="请输入手机号码" id="mobile" name="mobile">
                        </div>
						<div class="yzm-box2">
                            <div class="input-txt yzm">
                                <!--<i class="iconfont icon-anquan"></i>-->
                                <input type="text" placeholder="请输入数字验证码" id="captchanum" name="captchanum">
                            </div>
                            <div class="input-txt yzm-btn sendmsg send-standby" id="send-captcha-num">
                                <div id="img" class="am-fr" style=""></div>
                            </div>
                        </div>
                        <div class="yzm-box">
                            <div class="input-txt yzm">
                                <i class="iconfont icon-anquan"></i>
                                <input type="text" placeholder="请输入手机验证码" id="captcha" name="captcha">
                            </div>
                            <div class="input-txt yzm-btn sendmsg send-standby" id="send-captcha">                                
                                    发送验证码                                
                            </div>
                        </div>
                        <div class="input-txt" >
                            <i class="iconfont icon-suo"></i>
                            <input type="password" placeholder="请输入6-12位密码" id="password" name="password" >
                        </div>
                        <div class="input-txt">
                            <i class="iconfont icon-suo"></i>
                            <input type="password" placeholder="确认密码" id="password2" name="password2">
                        </div>
                        <div class="form-ft">
                            <a href="#11" class="login-btn" id="submit">重置密码</a>
							<a class="xy">&nbsp;</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>

<?php $this->load->view('home/pc/comm'); ?>

<script src="<?php echo $base_url?>static/dist/js/lib/jquery.min.js"></script>

<script>

    // 验证码
    function getCaptcha() {
        $.get("/admin/account/captcha", function (htmlStr) {
            img = '<img id="Imageid" src="/static/captcha/' + htmlStr + '">';
            $("#img").html($(img));
        })
    }
    getCaptcha();

    //刷新验证码
    $('#img').click(function () {
        getCaptcha();
    });

    //验证码倒计时
    var iTimer = 0;

    //发送验证码
    $('#send-captcha').on("click",function() {
        var mobile = $('#mobile').val();
        var captchanum = $('#captchanum').val();

        var pattern = /^1[34578]\d{9}$/;

        if (!pattern.test(mobile)) {
            alert("请填写11位数字的正确号码");
            return;
        }


        if (!navigator.onLine) {
            alert("网络连接异常，请检查网络");
            return;
        }
        if (captchanum == "") {
            alert("请输入数字验证码");
            return;
        }

        var self = this;
        // 验证码
        if ($(this).hasClass("send-standby")) {
            $.post("/home/account/sms_port_pc",{
                captcha:captchanum,
                phone:mobile,
                type:1
            }, function (json) {
                var json = eval(json);
                if (json.errcode != 0) { // 检验失败  手机号已存在等
                    alert(json.errmsg);
                    getCaptcha();
                    resetCaptchaBtn();
//                    if (json.errcode > 10030) {
//                        return;
//                    }

                } else { //  发送成功
                    timeCount();
                }
            }, 'json');
            // 写在这里可以防止重复点击
            $(self).removeClass("send-standby");
        }


    });

    function resetCaptchaBtn() {
        clearInterval(iTimer);
        $('#send-captcha').text('发送验证码');
        $('#send-captcha').addClass("send-standby");
    }

    //定时器
    function timeCount() {
        var i = 60;
        iTimer = setInterval(function() {
            i <= 0 ? clearInterval(iTimer) : i--;
            $('#send-captcha').text(i + '秒');
            if (i == 0) {
                resetCaptchaBtn();
            }
        }, 1000);
    }

    // 重置密码
    $('#submit').on("click",function() {
        var mobile = $('#mobile').val();
        var password = $('#password').val();
        var password2 = $('#password2').val();
        var captcha = $('#captcha').val();
        var pattern = /^1[34578]\d{9}$/;


        if (!pattern.test(mobile)) {
            alert("请填写11位数字的正确号码");
            return;
        }
        if (mobile == "" || password == "" || captcha == "") {
            alert("请填写手机号，密码和验证码");
            return;
        }

        if(password.length<6 || password.length>12){
            alert("请输入6-12位密码");
            return;
        }

        if (password != password2) {
            alert("您两次输入的密码不一致！");
            return;
        }

        //帮助登录
        $.post("<?php echo $base_url; ?>/home/account/updatePassword", {
            'mobile': mobile,
            'password': password,
            'captcha' : captcha
        }, function(json) {
            if (json.result == 0) {
                <?php if(empty($back_url)): ?>
                window.location.href = "<?php echo $base_url; ?>home";
                <?php else: //跳转到上一个页面?>
                window.location.href = decodeURIComponent("<?php echo urlencode($back_url); ?>");
                <?php endif; ?>
                return;
            }
            else
            {
                alert(json.message);
                return;
            }
        }, 'json');
    });

</script>

</body>

</html>
